<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<?php

use yii\helpers\Html;

?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"
            type="text/javascript"></script>
    <?php $this->head() ?>
    <link rel="canonical" href="<?= $base_url ?>/assets/public/css/AdminLTE.min.css"/>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<?php $this->beginBody() ?>
<div style="padding:10px">
    <div class="wrapper">
        <tr>
            <th colspan="2">
                <div class="form-group field-asraudio-start_end-1">
                    <label class="control-label">
                        <?php
                            if ($start_end==1){
                                echo "开始语";
                            }elseif ($start_end == 2){
                                echo "中间语";
                            }elseif ($start_end == 3){
                                echo "结束语";
                            }
                        ?></label>
                    <div class="help-block"></div>
                </div>
            </th>
        </tr>
        <!-- 	查询开始与结束的日期 -->
        <div class="form-group">


            <!--            ////////////////////////////////////////start//////////////////////////////////////////////////-->
            <?php
            $keyword = '';
            $k = $order;
            if (count($keywordids) > 0 && $k == "2") {
                foreach ($keywordids as $kk => $vv) {
                    $keywordModel = \app\models\AsrKeyword::findOne($vv['keyword_id']);
                    $keyword .= "<li><input  name=\'AsrKeyword[name][$keywordModel->keyword_id][]\'  readonly=\'readonly\' value=\'" . $keywordModel->name . "\'  style=\'border:0px;margin:10px 4px;\'><span class=\'pull-right badge bg-red\' data-id=\'" . $vv['keyword_id'] . "\' id=\'delete_$k" . "_" . "$keywordModel->name\' style=\'border:0px;margin:10px 4px;\'>删除</span></input></li>";
                }
            }
            $keyword = "\"" . $keyword . "\"";
            $file = '';
            if (count($fileids) > 0) {
                foreach ($fileids as $kk => $vv) {
                    $filesModel = \app\models\AsrFiles::findOne($vv['files_id']);
                    $filesize = round($filesModel->filesize / 1024, 1);
                    $file .= "<li><div  style='vertical-align: middle;background-color:#eeeeee33'>" .
                        "<audio controls='controls' style='height:48px;' >" .
                        "<source src='" . $base_url . $filesModel->filepath . "' type='audio/wav' />" .
                        "<source src='" . $base_url . $filesModel->filepath . "' type='audio/ogg' />" .
                        "<embed  src='" . $base_url . $filesModel->filepath . "' />" .
                        "</audio>" .
                        "         <input  name='AsrFiles[name][" . $vv['files_id'] . "][]' value='" . $filesModel->name . "     $filesize k'  style='border:0px;margin:0px 20px;'/>" .
                        "<span class='pull-right badge bg-red' data-id='" . $vv['files_id'] . "' id='delete_file_$k" . "_" . "$filesModel->name' style='border:0px;margin:10px 4px;'>删除</span></div></li>";
                }
            }
            $file = "\"" . $file . "\"";
            ?>
            <?php $form = \yii\widgets\ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data', 'id' => 'form_' . $k]]); ?>
            <input name="audio_id" hidden="hidden" value="<?= $audio_id ?>">
            <input name="order" hidden="hidden" value="<?= $k ?>">
            <input name="delete_keyword" id="delete_keyword" hidden="hidden" value="">
            <input name="delete_file" id="delete_file" hidden="hidden" value="">
            <table class="table table-bordered">
                <tbody>
                <tr>
                    <?php
                    if ($start_end == 2){
                    ?>
                    <td>
                        <label class="control-label">请输入关键字</label>
                        <input type="text" name="asrkeyword-name[<?= $k ?>]" id="asrkeyword-name_<?= $k ?>"
                               class="form-control" maxlength="30">
                        <div class="help-block"></div>
                        <div class="box box-widget widget-user-2">
                            <ul class="nav nav-stacked" style="max-height: 300px;overflow: auto;"
                                id="keyword_<?= $k ?>">
                            </ul>
                        </div>
                        <button type="button" id="addKeyword_<?= $k ?>" class="btn btn-default pull-right"
                                style="margin-top:20px;"><i
                                    class="fa fa-plus"></i> 新增关键字
                        </button>
                    </td>
                    <?php
                    }
                    ?>
                    <!-- !   请输入关键字-->
                    <td>
                        <div class="form-group  required">
                            <label class="control-label" for="asraudio-name">当检测到关键字-语音文件上传</label>
                            <?= $form->field(new \app\models\AsrFiles(), 'name[]')->widget(\kartik\file\FileInput::classname(), ['options' => ['accept' => 'pcm/wav', 'id' => 'select_files_' . $k . '', 'multiple' => false], 'pluginOptions' => [// 最多上传的文件个数限制
                                'maxFileCount' => 10,]])->label("") ?>
                            <div class="help-block"></div>
                            <div class="box box-widget widget-user-2">
                                <ul class="nav nav-stacked" style="max-height: 150px;overflow: auto"
                                    id="files_<?= $k ?>">
                                </ul>
                            </div>
                        </div>
                    </td>
                    <script>
                        $("#keyword_<?=$k?>").append(<?=$keyword?>);
                        $("#files_<?=$k?>").append(<?=$file?>);
                        $("span[id^='delete_<?=$k?>_']").click(function () {
                            if (confirm("是否删除该关键字？")) {
                                $("#delete_keyword").val($(this).attr("data-id"));
                                $("#form_<?=$k?>").attr('action', 'delete-keyword');
                                $("#save_<?=$k?>").submit();
                                $(this).parent().remove();
                            }
                        });
                        $("span[id^='delete_file_<?=$k?>_']").click(function () {
                            if (confirm("是否删除该文件？")) {
                                $("#delete_file").val($(this).attr("data-id"));
                                $("#form_<?=$k?>").attr('action', 'delete-file');
                                $("#save_<?=$k?>").submit();
                                $(this).parent().remove();
                            }
                        });
                        $("#addKeyword_<?=$k?>").click(function () {
                            var keyword = $("#asrkeyword-name_<?=$k?>").val();
                            if ($("#delete_<?=$k?>_" + keyword).length == 0 && keyword != "") {
                                $("#form_<?=$k?>").attr('action', 'create-keyword');
                                $("#save_<?=$k?>").submit();
                            } else {
                                alert("请重新输入关键字！");
                                $("#asrkeyword-name_<?=$k?>").focus();
                            }
                        });
                        //绑定按钮的点击事件让上传按钮隐藏
                        $("#select_files_<?=$k?>").bind('click', function () {
                            $("#form_<?=$k?>").attr("action", "create-file");
                        })
                    </script>
                    <!-- !   当检测到关键字-语音文件上传-->
                </tr>
                </tbody>
            </table>
            <!-- !   保存-->
            <div class="form-group"<?= count($keywordids) != 0 && count($fileids) != 0 ?> hidden="hidden">
                <?= Html::submitButton('保存', ['class' => 'btn btn-info', 'id' => 'save_' . $k]) ?>
            </div>
            <?php \yii\widgets\ActiveForm::end(); ?>
            <!--            /////////////////////////////////////////end/////////////////////////////////////////////////-->


        </div>
    </div>
</div>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
